package com.axjy.controller;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.axjy.pojo.YiCard;
import com.axjy.pojo.YiCardUser;
import com.axjy.service.YiCardService;
import com.axjy.service.YiCardUserService;
import com.axjy.util.Pager;

@Controller
public class YiCardController {

	@Resource
	private YiCardService yiCardService;
	@Resource
	private YiCardUserService yiCardUserService;
	
	@RequestMapping("/yiCardJsp")
	public String yiCardJsp(Model model) {
		int yId=yiCardService.searYiCardId();
		model.addAttribute("yId", yId+1);
		return "qiantai/yiCard";
	}
	
	@ResponseBody
	@RequestMapping("/yiCard")
	public Pager yiCard(Integer offset,Integer limit,String columnName,String columnValue) {
		return yiCardService.pager(offset, limit, columnName, columnValue);
	}
	
	@ResponseBody
	@RequestMapping("/addYC")
	public String addYC(YiCardUser yiCardUser,YiCard yiCard,String uCard) {
		yiCardUserService.addYiCardUser(yiCardUser);
		int uId=yiCardUserService.searchuId(uCard);
		yiCard.setuId(uId);
		int res=yiCardService.addYiCard(yiCard);
		if(res>0) {
			return "success";
		}
		return "fail";
	}
	
	@ResponseBody
	@RequestMapping("/backYC")
	public String backYC(Integer yId,YiCardUser yiCardUser) {
		int res1=yiCardService.delYiCard(yId);
		int res2=yiCardUserService.updateState(yiCardUser);
		if(res1>0) {
			return "success";
		}
		return "fail";
	}
	
	@ResponseBody
	@RequestMapping("/chongMoney")
	public String chongMoney(YiCard yiCard,Double cMoney,Double yMoney) {
		yiCard.setyMoney(yMoney+cMoney);
		int res=yiCardService.updateMoney(yiCard);
		if(res>0) {
			return "success";
		}
		return "fail";
	}
}
